//------------------------------------------------------------------------------
#include "CMyGroupBox.h"
//------------------------------------------------------------------------------
CMyGroupBox::CMyGroupBox(QWidget *parent) : QGroupBox(parent), CChampText()
{
	setDataType(CCommun::edtString);
}
//------------------------------------------------------------------------------
QString CMyGroupBox::getValue(void)
{
	QList<CMyRadioButton *> objects = findChildren<CMyRadioButton *>();
	
	foreach(CMyRadioButton *object, objects)
	{
		if(object->isChecked())
		{
			return object->getValueIfSelected();
		}
	}
	return "";
}
//------------------------------------------------------------------------------
void CMyGroupBox::setValue(QVariant value)
{
	QList<CMyRadioButton *> objects = findChildren<CMyRadioButton *>();
	
	foreach(CMyRadioButton *object, objects)
	{ 	
		object->setChecked(object->getValueIfSelected() == value.toString());
	}
}
//------------------------------------------------------------------------------
void CMyGroupBox::setStateEnable(bool enable)
{
	if(_standaloneEnable)
	{
		setEnabled(enable);
	}
}
//------------------------------------------------------------------------------
void CMyGroupBox::setAttribut(EAttribut)
{
	/*QString styleSheet="color: %1; font-weight: %2;";
	QString color="black;";
	QString weight="normal";
	
	_attribut=value;
	
	if(value & atObligatoire)
	{
		color="#FF0000;";
		weight="bold";
	}
	if(value & atObligatoireConditionel)
	{
		color="#0000FF;";
		weight="bold";
		setToolTip(getTextCondition());
	}
	
	setStyleSheet(styleSheet.arg(color).arg(weight));*/
}
//------------------------------------------------------------------------------
void CMyGroupBox::setTextCondition(QString value)
{
	_textCondition=value;
	if(getAttribut() & atObligatoireConditionel)
	{
		setToolTip(value);
	}
}
//------------------------------------------------------------------------------
bool CMyGroupBox::isEmpty(void)
{
	QList<CMyRadioButton *> objects = findChildren<CMyRadioButton *>();
	
	foreach(CMyRadioButton *object, objects)
	{
		if(object->isChecked()) return false;
	}
	
	return true;
}
//------------------------------------------------------------------------------
void CMyGroupBox::keyPressEvent(QKeyEvent * event)
{
	if(event->key() == Qt::Key_F1)
	{
		emit invokeHelp(this);
	}
	QGroupBox::keyPressEvent(event);
}
//------------------------------------------------------------------------------
void CMyGroupBox::onChange(void)
{
	emit change();
}	
//------------------------------------------------------------------------------
void CMyGroupBox::onToggledRadioButtons(void)
{
	emit toggledRadioButtons();
}
//------------------------------------------------------------------------------
